home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 114 / macaddict114.cdr / Software / Utilities / macam.0.8.4.dmg / macam sources / driver_core / MyCameraCentral.h next >
Encoding:
C/C++ Source or Header  |  2003-12-22  |  6.3 KB  |  115 lines

  1. /*
  2.  macam - webcam app and QuickTime driver component
  3.  Copyright (C) 2002 Matthias Krauss (macam@matthias-krauss.de)
  4.  
  5.  This program is free software; you can redistribute it and/or modify
  6.  it under the terms of the GNU General Public License as published by
  7.  the Free Software Foundation; either version 2 of the License, or
  8.  (at your option) any later version.
  9.  
  10.  This program is distributed in the hope that it will be useful,
  11.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  GNU General Public License for more details.
  14.  
  15.  You should have received a copy of the GNU General Public License
  16.  along with this program; if not, write to the Free Software
  17.  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  $Id: MyCameraCentral.h,v 1.6 2003/12/22 01:23:24 mattik Exp $
  19.  */
  20.  
  21. #import <Cocoa/Cocoa.h>
  22. #include "GlobalDefs.h"
  23. #import "MyCameraDriver.h"
  24. #import "MyCameraInfo.h"
  25.  
  26. /*
  27.  This is the plot of MyCameraCentral and the relationship between the Camera driver itself and the client: Consider this as a combined camera database and factory. A client first instantiates a CameraCentral and sets itself as its delegate (the client only has ONE CameraCentral - it's a singleton although this is not enforced but results will be probably terrible if you don't do so). Then the client calls [startup]. This will do two things: First, it will look through all available camera types and ask them for their usb signature (type/vendor id). After that, the USB notification process is started.
  28.  
  29.  If a new camera is detected and the device matches one of the camera types, the delegate will be notified by [cameraDetected] with an unique number identifying the camera. The delegate may now reply by using [useCamera] with the id received by the delegate method. If everything is fine, will get a ready-to-use CameraDriver object for the camera - with the delegate already set to the client. But you can change the delegate if you wish. It is also kept in a list of active cameras by the camera centrral.
  30.  
  31.  If a camera is unplugged, the camera central will detect this and look in its list of active cameras if that camera is currently in use. If yes, the central will [shutdown] the camera, which will notify the client about it by calling the delegate's [cameraHasShutDown]. This indicates the client that the camera driver object is finished and can be released by the client. The camera will also notify its center about the [shutdown] which will remove the driver from the list of active drivers and release that object.
  32.  
  33.  The benefit of this is that client may also simply [shutdown] the camera. It will behave identical to the cameraHasShutDown procedure. The only difference is that the camera central will know that it hasn't been really unplugged and keep the camera in its list of available cameras which can be browsed.
  34.  
  35.  The way for the client to shut everything down is to call the camera central's [shutdown]. This will stop the notification process and shut down all cameras.
  36.  
  37.  Note that in older versions, there was a dedicated thread for the USB plugging notification stuff: wiringThread. Unfortunately, this mechanism conflicted with some other applications (since this thread will also be started when macam is used as a QuickTime VDIG component and the component will start the thread in all cases - no matter if the application actually uses a VDIG - and some applications had problems with threads that were not caused by them). So all the functionality was put into the main thread.
  38.  
  39.  */
  40. @interface MyCameraCentral : NSObject {
  41.     NSMutableArray* cameraTypes;    //A list of dictionaries containing long "vendorID", long "productID" and class "class"
  42.     NSMutableArray* cameras;        //A list of cameras currently connected
  43. /* Why is this ana array and not a dictionary keyed by cid? This will make enumeration simpler - if we implement browsing in the cameras later. On the other hand, finding a cam by cid now requires walking through the array. That's not too bad since that array will probably never be so big...*/
  44.  
  45.     IBOutlet id delegate;
  46.     BOOL doNotificationsOnMainThread;
  47.     BOOL recognizeLaterPlugins;
  48.     
  49. //Localized error messages
  50.     char localizedErrorCStrs[10][256];
  51.     char localizedUnknownErrorCStr[256];
  52.  
  53.     IONotificationPortRef notifyPort;    //Port for notifications from IOKit to mainThread
  54.  
  55.  
  56. }
  57.  
  58. //Access to the shared instance of MyCameraCentral
  59. + (MyCameraCentral*) sharedCameraCentral;
  60.  
  61. //See if someone has requested (and therefore initialized) MyCameraCentral before
  62. + (BOOL) isCameraCentralExisting;
  63.  
  64. //Localization services - we may be in an external application so system services won't work dirctly. Make sure you have an an AutoreleasePool
  65. + (NSString*) localizedStringFor:(NSString*) str;
  66.  
  67. //The same for cstr stuff. This one makes an AutoreleasePool on its own
  68. + (void) localizedCStrFor:(char*)key into:(char*)value;
  69.  
  70. //A Quicker way - localized error names are cached (for displaying speed purposes)
  71. - (char*) localizedCStrForError:(CameraError)err;
  72.  
  73. //Init, startup, shutdown, dealloc
  74.  
  75. - (void) dealloc;
  76. - (BOOL) startupWithNotificationsOnMainThread:(BOOL)nomt recognizeLaterPlugins:(BOOL)rlp;
  77. //You should have set the delegate when calling this. Returns success.
  78.  
  79. - (void) shutdown;    //Stops all cams and stops USB notification process
  80.  
  81. //Property get/set
  82.  
  83. - (id) delegate;
  84. - (void) setDelegate:(id)d;
  85. - (BOOL) doNotificationsOnMainThread;
  86.  
  87. //Camera management
  88.  
  89. - (short) numCameras;
  90. - (short) indexOfCamera:(MyCameraDriver*)driver;
  91. - (unsigned long) idOfCameraWithIndex:(short)idx;
  92. - (unsigned long) idOfCameraWithLocationID:(UInt32)locID;
  93. - (CameraError) useCameraWithID:(unsigned long)cid to:(MyCameraDriver**)outCam acceptDummy:(BOOL)acceptDummy;
  94. - (MyCameraDriver*) useDummyForError:(CameraError)err;
  95. - (NSString*) nameForID:(unsigned long)cid;
  96. - (NSString*) nameForDriver:(MyCameraDriver*)driver;
  97. - (BOOL) getName:(char*)name forID:(unsigned long)cid;
  98. - (BOOL) getName:(char*)name forDriver:(MyCameraDriver*)driver;
  99.  
  100. //Camera defaults managements
  101. - (BOOL) setCameraToDefaults:(MyCameraDriver*) camera;
  102. - (BOOL) saveCameraSettingsAsDefaults:(MyCameraDriver*) camera;
  103.  
  104. //wiring stuff
  105. - (void) deviceRemoved:(unsigned long)cid;
  106. - (void) deviceAdded:(io_iterator_t)iterator info:(MyCameraInfo*)info;
  107.  
  108. //delegate forwarders
  109. - (void) cameraDetected:(unsigned long)cid;
  110.  
  111. //Notification from running camera
  112. - (void) cameraHasShutDown:(id)sender;
  113.  
  114. @end
  115.